package java_collection.lab;

import java.util.HashSet;
import java.util.Set;

// boolean add(E e), return false If this set already contains the element
//  HashSet stores its elements in a hash table, is the best-performing implementation;
// however it makes no guarantees concerning the order of iteration

public class FindDups {

	public static void main(String[] args) {
		String para = "i came i saw i left";
		String[] word = para.split(" ");
		
		Set<String> s = new HashSet<String>();
        for (String a : word)
            if (!s.add(a))
                System.out.println("Duplicate detected: " + a);

        System.out.println(s.size() + " distinct words: " + s);

	}

}

/*
 * Duplicate detected: i
*  Duplicate detected: i
*  4 distinct words: [left, saw, came, i]
 */
